package org.zs.miracle.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.AllArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.zs.miracle.common.base.dto.BaseManyLongIdDTO;
import org.zs.miracle.common.base.web.BaseController;
import org.zs.miracle.service.role.IRoleService;
import org.zs.miracle.service.role.model.dto.AddRoleInputDTO;
import org.zs.miracle.service.role.model.dto.EditRoleDTO;
import org.zs.miracle.service.role.model.dto.RolePageQueryDTO;
import org.zs.miracle.service.role.model.dto.RoleUserModel;
import org.zs.miracle.service.role.model.dto.SetRoleStateDTO;
import org.zs.miracle.service.role.model.dto.SetRoleUserInputDTO;
import org.zs.miracle.service.role.model.vo.RolePageQueryListItemVo;
import org.zs.miracle.service.role.model.vo.RoleVo;

@Tag(name = "角色接口")
@AllArgsConstructor
@RestController
@RequestMapping("/role")
public class RoleController extends BaseController {
  
  IRoleService roleService;
  
  @Operation(summary = "分页查询", description = "分页查询角色接口")
  @GetMapping(value = "/pageQueryList", produces = MediaType.APPLICATION_JSON_VALUE)
  
  public Page<RolePageQueryListItemVo> pageQueryList(RolePageQueryDTO inputDTO) {
    return roleService.pageQueryList(inputDTO);
  }
  
  @Operation(summary = "根据状态查询角色", description = "根据角色启用状态查询")
  @GetMapping(value = "/queryList", produces = MediaType.APPLICATION_JSON_VALUE)
  @Parameters({
      @Parameter(name = "enable", description = "true|false|不传递,true查询启用,false=查询禁用,不传入=查询全部"),
  })
  
  public List<RoleVo> queryList(Boolean enable) {
    return roleService.queryList(enable);
  }
  
  @Operation(summary = "查询角色下的用户", description = "查询指定角色下有哪些用户")
  @GetMapping(value = "/queryRoleUserList", produces = MediaType.APPLICATION_JSON_VALUE)
  @Parameters({
      @Parameter(name = "id", description = "角色id"),
  })
  
  public List<RoleUserModel> queryRoleUserList(@RequestParam(name = "id") Long id) {
    return roleService.queryRoleUserList(id);
  }
  
  @Operation(summary = "角色设置用户", description = "批量给角色设置用户")
  @ApiResponse(responseCode = "200", description = "ok")
  @PostMapping(value = "/setRoleUser", produces = MediaType.APPLICATION_JSON_VALUE)
  public Boolean setRoleUser(@RequestBody @Validated SetRoleUserInputDTO inputDTO) {
    return roleService.setRoleUser(inputDTO);
  }
  
  @Operation(summary = "添加角色")
  @ApiResponse(responseCode = "200", description = "ok")
  @PostMapping(value = "/addRole", produces = MediaType.APPLICATION_JSON_VALUE)
  public Boolean addRole(@RequestBody @Validated AddRoleInputDTO inputDTO) {
    return roleService.addRole(inputDTO);
  }
  
  @Operation(summary = "编辑角色")
  @ApiResponse(responseCode = "200", description = "ok")
  @PatchMapping(value = "/editRole", produces = MediaType.APPLICATION_JSON_VALUE)
  public Boolean editRole(@RequestBody @Validated EditRoleDTO inputDTO) {
    return roleService.editRole(inputDTO);
  }
  
  @Operation(summary = "启用|停用角色", description = "启用|停用角色接口")
  @ApiResponse(responseCode = "200", description = "OK")
  @PatchMapping(value = "/setState", produces = MediaType.APPLICATION_JSON_VALUE)
  public Boolean setState(@RequestBody @Validated SetRoleStateDTO inputDTO) {
    return roleService.setState(inputDTO);
  }
  
  @Operation(summary = "删除角色")
  @ApiResponse(responseCode = "200", description = "OK")
  @DeleteMapping(value = "/delRole", produces = MediaType.APPLICATION_JSON_VALUE)
  public Boolean delRole(@RequestBody @Validated BaseManyLongIdDTO inputDTO) {
    return roleService.delRole(inputDTO);
  }
}